package com.pango.core.easyui.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.pango.core.utils.StringUtils;
/**
 * 
 * @author thierry.fu
 *
 */
public class BaseTag extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected String type = "default";// 加载类型

	public void setType(String type) {
		this.type = type;
	}

	
	public int doStartTag() throws JspException {
		return EVAL_PAGE;
	}

	/**
	 * 页面自动导入Js和CSS样式
	 */
	public int doEndTag() throws JspException {
		try {
			JspWriter out = this.pageContext.getOut();
			StringBuffer sb = new StringBuffer();

			String types[] = type.split(",");
			//avoid favicon.ico 
			sb.append("<link rel=\"shortcut icon\" href=\"data:image/x-icon;,\" type=\"image/x-icon\">");
			if (StringUtils.isIn("jquery", types)) {
				sb.append("<script type=\"text/javascript\" src=\"static/js/vendor/jquery-1.8.3.js\"></script>");
			}
			if (StringUtils.isIn("easyui", types)) {
				sb.append("<link id=\"easyuiTheme\" rel=\"stylesheet\" href=\"static/css/themes/default/easyui.css\" type=\"text/css\"></link>");
				sb.append("<link rel=\"stylesheet\" href=\"/static/css/themes/icon.css\" type=\"text/css\"></link>");
				sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/themes/icon.css\">");
				sb.append("<script type=\"text/javascript\" src=\"/static/js/vendor/easyui/jquery.easyui.min.js\"></script>");
			}
			if (StringUtils.isIn("DatePicker", types)) {
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/My97DatePicker/WdatePicker.js\"></script>");
			}
			if (StringUtils.isIn("tools", types)) {
				sb.append("<link rel=\"stylesheet\" href=\"/static/plugin/tools/css/common.css\" type=\"text/css\"></link>");
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/lhgDialog/lhgdialog.min.js\"></script>");
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/tools/curdtools.js\"></script>");
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/tools/easyuiextend.js\"></script>");
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/tools/syUtil.js\"></script>");
				sb.append("<script type=\"text/javascript\" src=\"/static/plugin/tools/datagrid-scrollview.js\"></script>");
			}
			out.print(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}
}
